package orlowski.kamil.simple.app.activity;

import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.view.View;
import orlowski.kamil.simple.app.MainApplication;
import orlowski.kamil.simple.app.adapter.CountryListAdapter;
import orlowski.kamil.simple.app.domain.Country;
import android.app.Instrumentation.ActivityMonitor;

import java.util.List;

/**
 * Created by Kamil on 2014-10-20.
 * Menu tests
 */
public class MenuListActivityTests extends ActivityInstrumentationTestCase2<MenuListActivity> {
    public MenuListActivityTests() {
        super(MenuListActivity.class);
    }

    /**
     * Test wykorzystujacy instrumentyzacje, na urzadzeniu mozna zaobserwowac
     * jak biblioteka symuluje kontakt z uzytkownikiem
     * @throws Exception
     */
    public void testMenuListToDetailsUserFlow() throws Exception {
        Instrumentation instr = getInstrumentation();
        MenuListActivity menuList = getActivity();

        List<Country> countryList = menuList.getCountryList();
        MainApplication mainApplication = menuList.getMainApplication();
        CountryListAdapter adapter = menuList.getAdapter();

        assertNotNull("task should not be null", countryList);
        assertNotNull("task should not be null", mainApplication);
        assertNotNull("task should not be null", adapter);

        instr.waitForIdleSync();

        String detailActivity = MenuListActivity.class.getCanonicalName();
        ActivityMonitor monitor = instr.addMonitor(detailActivity, null, false);

        View firstItem = menuList.getListView().getChildAt(0);
        TouchUtils.clickView(this, firstItem);

        instr.removeMonitor(monitor);
    }
}
